home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / ReplaceConfirmDialog.java < prev    next >
Text File  |  1998-11-01  |  5KB  |  200 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class ReplaceConfirmDialog extends Dialog {
  8.     FindReplaceEngine FRE;
  9.     
  10.     public ReplaceConfirmDialog(Frame parent, boolean modal)
  11.     {
  12.         super(parent, modal);
  13.  
  14.         // This code is automatically generated by Visual Cafe when you add
  15.         // components to the visual environment. It instantiates and initializes
  16.         // the components. To modify the code, only use code syntax that matches
  17.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  18.         // parse your Java file into its visual environment.
  19.         //{{INIT_CONTROLS
  20.         setLayout(null);
  21.         setBackground(java.awt.Color.lightGray);
  22.         setSize(261,71);
  23.         setVisible(false);
  24.         confirmlabel.setText("Replace this occurrence?");
  25.         add(confirmlabel);
  26.         confirmlabel.setBounds(48,12,166,21);
  27.         btnYes.setActionCommand("button");
  28.         btnYes.setLabel("Yes");
  29.         add(btnYes);
  30.         btnYes.setBounds(10,39,45,22);
  31.         btnNo.setActionCommand("button");
  32.         btnNo.setLabel("No");
  33.         add(btnNo);
  34.         btnNo.setBounds(68,39,45,22);
  35.         btnCancel.setActionCommand("button");
  36.         btnCancel.setLabel("Cancel");
  37.         add(btnCancel);
  38.         btnCancel.setBounds(126,39,45,22);
  39.         cb_confirm.setLabel("Confirm");
  40.         add(cb_confirm);
  41.         cb_confirm.setBounds(184,39,69,18);
  42.         setTitle("Dialog2");
  43.         //}}
  44.         
  45.         
  46.         //{{REGISTER_LISTENERS
  47.         SymWindow aSymWindow = new SymWindow();
  48.         addWindowListener(aSymWindow);
  49.         SymAction lSymAction  = new SymAction();
  50.         btnYes.addActionListener(lSymAction);
  51.         btnNo.addActionListener(lSymAction);
  52.         btnCancel.addActionListener(lSymAction);
  53.         this.addWindowListener(aSymWindow);
  54.         //}}
  55.  
  56.     }
  57.     
  58.     public void addNotify()
  59.     {
  60.         // Record the size of the window prior to calling parents addNotify.
  61.         Dimension d = getSize();
  62.         
  63.         super.addNotify();
  64.  
  65.         if (fComponentsAdjusted)
  66.             return;
  67.  
  68.         // Adjust components according to the insets
  69.         Insets insets = getInsets();
  70.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  71.         Component components[] = getComponents();
  72.         for (int i = 0; i < components.length; i++)
  73.         {
  74.             Point p = components[i].getLocation();
  75.             p.translate(insets.left, insets.top);
  76.             components[i].setLocation(p);
  77.         }
  78.         fComponentsAdjusted = true;
  79.     }
  80.  
  81.  
  82.     // Used for addNotify check.
  83.     boolean fComponentsAdjusted = false;
  84.  
  85.  
  86.     public ReplaceConfirmDialog(Frame parent, String title, boolean modal, FindReplace replace)
  87.     {
  88.         this(parent, modal);
  89.         setTitle(title);
  90.         m_replace = replace;
  91.         FRE = new FindReplaceEngine(m_replace);
  92.     }
  93.  
  94.     
  95.  
  96.     //{{DECLARE_CONTROLS
  97.     java.awt.Label confirmlabel = new java.awt.Label();
  98.     java.awt.Button btnYes = new java.awt.Button();
  99.     java.awt.Button btnNo = new java.awt.Button();
  100.     java.awt.Button btnCancel = new java.awt.Button();
  101.     java.awt.Checkbox cb_confirm = new java.awt.Checkbox();
  102.     //}}
  103.     FindReplace m_replace;
  104.     
  105.     private void replace()
  106.     {
  107.         if(m_replace.isFoundIt()) {
  108.             m_replace.setIndex(FRE.ReplaceIt());
  109.             if(cb_confirm.getState()) {
  110.                 FRE.ReplaceAll();
  111.             }
  112.         }    
  113.        find();
  114.     }
  115.     
  116.     public void find()
  117.     {
  118.         FRE.FindIt();
  119.     }
  120.     
  121.     class SymWindow extends java.awt.event.WindowAdapter
  122.     {
  123.         public void windowClosing(java.awt.event.WindowEvent event)
  124.         {
  125.             Object object = event.getSource();
  126.             if (object == ReplaceConfirmDialog.this)
  127.                 ReplaceConfirmDialog_WindowClosing(event);
  128.         }
  129.     }
  130.     
  131.     void ReplaceConfirmDialog_WindowClosing(java.awt.event.WindowEvent event)
  132.     {
  133.         ReplaceConfirmDialog_WindowClosing_Interaction1(event);
  134.     }
  135.  
  136.     void ReplaceConfirmDialog_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
  137.     {
  138.         try {
  139.             this.dispose();
  140.         } catch (Exception e) {
  141.         }
  142.     }
  143.     
  144.     class SymAction implements java.awt.event.ActionListener
  145.     {
  146.         public void actionPerformed(java.awt.event.ActionEvent event)
  147.         {
  148.             Object object = event.getSource();
  149.             if (object == btnYes)
  150.                 btnYes_ActionPerformed(event);
  151.             else if (object == btnNo)
  152.                 btnNo_ActionPerformed(event);
  153.             else if (object == btnCancel)
  154.                 btnCancel_ActionPerformed(event);
  155.         }
  156.     }
  157.  
  158.     void btnYes_ActionPerformed(java.awt.event.ActionEvent event)
  159.     {
  160.         // to do: code goes here.
  161.  
  162.         btnYes_ActionPerformed_Interaction1(event);
  163.     }
  164.  
  165.     void btnYes_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  166.     {
  167.         try {
  168.             this.replace();
  169.         } catch (Exception e) {
  170.         }
  171.     }
  172.     
  173.     void btnNo_ActionPerformed(java.awt.event.ActionEvent event)
  174.     {
  175.         btnNo_ActionPerformed_Interaction1(event);
  176.     }
  177.  
  178.     void btnCancel_ActionPerformed(java.awt.event.ActionEvent event)
  179.     {
  180.         btnCancel_ActionPerformed_Interaction1(event);
  181.     }
  182.  
  183.     void btnCancel_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  184.     {
  185.         try {
  186.             this.dispose();
  187.         } catch (Exception e) {
  188.         }
  189.     }
  190.  
  191.     void btnNo_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  192.     {
  193.         try {
  194.             this.find();
  195.         } catch (Exception e) {
  196.         }
  197.     }
  198.  
  199. }
  200.